<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="retiresPayrollList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>

      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="生活补贴">
              <span>{{ props.row.livingallowance }}</span>
            </el-form-item>
            <el-form-item label="住房改革补贴">
              <span>{{ props.row.housingreformsubsidies }}</span>
            </el-form-item>
            <el-form-item label="退休人员慰问金">
              <span>{{ props.row.solatiumforretirees }}</span>
            </el-form-item>
            <el-form-item :label=item.subsidyprojectName v-for="(item, index,) in props.row.floatingItems">
              <span v-text="item.subsidyprojectMoney"></span>
            </el-form-item>
            <el-divider></el-divider>
            <el-form-item label="合计">
              <span>{{ props.row.retireesPayrollTotal }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>

      <el-table-column label="工号" align="center" prop="jobNumber"/>
      <el-table-column label="姓名" align="center" prop="nickName"/>
      <el-table-column label="工资年月" align="center" prop="retireespayrollDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.retireespayrollDate, '{y}-{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合计" align="center" prop="retireesPayrollTotal"/>
      <el-table-column label="备注" align="center" prop="retireespayrollRemarks"/>
      <el-table-column label="确认状态" align="center" prop="auditStatus">
        <template slot-scope="{row}">
          <el-tag
            type="info"
            v-show="row.auditStatus===0"
          >
            未确定
          </el-tag>
          <el-tag
            type="success"
            v-show="row.auditStatus===1"
          > 确定
          </el-tag>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            v-hasPermi="['compensationManagement:viewSelfRetiresPayroll:query']"
          >查看
          </el-button>
        </template>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 查看个人退休人员补贴工资对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">

        <el-form-item label="工号" prop="jobNumber">
          <el-input v-model="form.jobNumber" :disabled="form.retireespayrollId!=null"
                    placeholder="请输入工号"
          />
        </el-form-item>
        <el-form-item label="姓名" prop="nickName">
          <el-input v-model="form.nickName" :disabled="form.retireespayrollId!=null"/>
        </el-form-item>
        <el-form-item label="工资年月" prop="retireespayrollDate">
          <el-date-picker clearable
                          v-model="form.retireespayrollDate"
                          type="month"
                          value-format="yyyy-MM"
                          placeholder="请选择工资年月"
                          :disabled="form.retireespayrollId!=null"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="生活补贴" prop="livingallowance">
          <el-input-number v-model="form.livingallowance" :disabled=true
                           :precision="2" controls-position="right" :min="0" :step="0.1"
          ></el-input-number>
        </el-form-item>
        <el-form-item label="住房改革补贴" prop="housingreformsubsidies">
          <el-input-number v-model="form.housingreformsubsidies" :disabled=true
                           :precision="2" controls-position="right" :min="0"
                           :step="0.1"
          ></el-input-number>
        </el-form-item>
        <el-form-item label="退休人员慰问金" prop="solatiumforretirees">
          <el-input-number v-model="form.solatiumforretirees" :disabled=true
                           :precision="2" controls-position="right" :min="0"
                           :step="0.1"
          ></el-input-number>
        </el-form-item>

        <el-form-item
          v-for="(domain, index) in form.floatingItems"
          :label="'浮动项目' + (index+1)"
          :prop="'floatingItems.' + index + '.subsidyprojectId'"
          :key="domain.subsidyprojectId"
        >
          <el-row :gutter="4">
            <el-col :span="5">
              <el-input v-model="domain.subsidyprojectName" :disabled=true></el-input>
            </el-col>
            <el-col :span="5">
              <el-input-number placeholder="补贴项目金额"
                               :precision="2" v-model="domain.subsidyprojectMoney"
                               controls-position="right"
                               :min="0"
                               :step="0.1"
                               :disabled=true
              ></el-input-number>
            </el-col>
          </el-row>
        </el-form-item>
        <el-row>
          <el-divider></el-divider>
          <el-col>
            <el-form-item label="实发数" prop="retireesPayrollTotal">
              <el-input-number :disabled="true" v-model="form.retireesPayrollTotal" :precision="2"
                               controls-position="right"
                               :min="0"
                               :step="0.1"
              ></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="备注" prop="retireespayrollRemarks">
          <el-input v-model="form.retireespayrollRemarks" type="textarea" :disabled=true />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {

  listSelfRetiresPayroll, getSelfRetiresPayroll
} from '@/api/compensationManagement/retiresPayroll'

export default {
  name: 'ViewSelfRetirespayroll',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 退休人员补贴工资表格数据
      retiresPayrollList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询退休人员补贴工资列表 */
    getList() {
      this.loading = true
      listSelfRetiresPayroll(this.queryParams).then(response => {
        this.retiresPayrollList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        retireespayrollId: null,
        jobNumber: null,
        nickName: null,
        retireespayrollDate: null,
        livingallowance: null,
        housingsubsidy: null,
        housingreformsubsidies: null,
        solatiumforretirees: null,
        retireespayrollTotal: null,
        retireespayrollRemarks: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.retireespayrollId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.reset()
      console.log(row)
      const retireespayrollId = row.retireespayrollId || this.ids
      console.log(retireespayrollId+"++++++++")
      getSelfRetiresPayroll(retireespayrollId).then(response => {
        this.form = response.data.fixedItems
        this.form.floatingItems = response.data.floatingItems
        this.open = true
        this.title = '修改退休人员补贴工资'
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('compensationManagement/retiresPayroll/export', {
        ...this.queryParams
      }, `retiresPayroll_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>

<style>
.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  width: 110px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 1%;
  margin-bottom: 0;
  width: 100%;
}
</style>
